﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Factory.cs" company="Data Ductus Malmö">
//   (c) 2010 - 2012 Data Ductus Malmö AB
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace DataDuctus.Snmp.Persistor.Core.Tests.Internal
{
  using System.Collections.Generic;

  using DataDuctus.Snmp.Persistor.Core.MetaData;
  using DataDuctus.Snmp.Persistor.Core.Persistor;
  using DataDuctus.Snmp.Persistor.Core.Tests.TestData;
  using DataDuctus.Snmp.Persistor.Core.Tests.TestData.Agent;

  /// <summary>
  /// The factory.
  /// </summary>
  internal static class Factory
  {
    #region Methods

    /// <summary>
    /// The get entity factory.
    /// </summary>
    /// <returns>
    /// The SnmpPersistor.Core.Persistor.EntityPersistorFactory.
    /// </returns>
    internal static EntityPersistorFactory GetEntityFactory()
    {
      return GetEntityFactory(GetConfiguration());
    }

    /// <summary>
    /// The get configuration.
    /// </summary>
    /// <returns>
    /// The SnmpPersistor.Core.MetaData.Configuration.
    /// </returns>
    private static Configuration GetConfiguration()
    {
      return
        new Configuration().Add(typeof(Interface)).Add(typeof(InterfaceIpAddress)).Add(typeof(TcpConnection)).Add(
          typeof(WindowsService)).Add(typeof(SystemInfo)).Add(typeof(Route)).Add(typeof(NetMedia)).Add(
            typeof(ServiceConfig));
    }

    /// <summary>
    /// The get connections.
    /// </summary>
    /// <returns>
    /// The System.Collections.Generic.IEnumerable`1[T -&gt; SnmpPersistor.Core.MetaData.ConnectionMeta].
    /// </returns>
    private static IEnumerable<ConnectionMeta> GetConnections()
    {
      return new[]
        {
          ConnectionMeta.FromUrl("snmp://localhost:161/v2c/read/public"), 
          ConnectionMeta.FromUrl("snmp://localhost:161/v2c/write/private")
        };
    }

    /// <summary>
    /// The get entity factory.
    /// </summary>
    /// <param name="config">
    /// The config.
    /// </param>
    /// <returns>
    /// The SnmpPersistor.Core.Persistor.EntityPersistorFactory.
    /// </returns>
    private static EntityPersistorFactory GetEntityFactory(Configuration config)
    {
      return new EntityPersistorFactory(config, GetConnections());
    }

    #endregion
  }
}